﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;

namespace gChartSharp
{
    public class MapChart : ChartBase
    {
        public override ChartType ChartType { get { return ChartType.Map; } }


        #region Member Variables
        private GeographicalAreaParam mGeographicalArea;
        private SubRegionParam mSubregion;
        private MapColorParam mColor;
        private SolidFillParam mBackground;
        #endregion


        #region Properties
        public GeographicalAreaParam GeographicalArea
        {
            get { return mGeographicalArea ?? (mGeographicalArea = new GeographicalAreaParam()); }
            set { mGeographicalArea = value; }
        }


        public SubRegionParam SubRegions
        {
            get { return mSubregion ?? (mSubregion = new SubRegionParam()); }
            set { mSubregion = value; }
        }


        public MapColorParam MapColor
        {
            get { return mColor ?? (mColor = new MapColorParam()); }
            set { mColor = value; }
        }


        public SolidFillParam Background
        {
            get { return mBackground ?? (mBackground = new SolidFillParam()); }
            set { mBackground = value; }
        }
        #endregion


        public MapChart(int width, int height, GeographicalArea geoArea)
        {
            if (width > 440 || height > 220)
                throw new ChartException("MapChart size cannot exceed 440x220.");

            Size = new SizeParam(width, height);
            Data = new DataSeriesParam() { EncodingType = EncodingType.Simple };
            GeographicalArea = new GeographicalAreaParam() { GeographicalArea = geoArea };
            Background = new SolidFillParam(SolidFillType.bg, Color.White);
        }

   
        public override string Render()
        {
            if (Data.Params.Count > 0)
            {
                if (this.Data.Params.Count > 1)
                    throw new ChartException("Only one data set is allowed for a MapChart.");

                if (Data.Params[0].Length == this.SubRegions.Countries.Count || Data.Params[0].Length == this.SubRegions.US_States.Count)
                    return RenderUrl();
                else
                    throw new ChartException("The number of SubRegions must match the number of data points.");
            }
            else
            {
                return RenderUrl();
            }
        }
    }





} 